<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="流程名称">
                <a-input v-model="queryParam.wfName" placeholder="流程名称" allow-clear/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="流程分类">
                <a-input v-model="queryParam.wfCategory" placeholder="流程分类" allow-clear/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
              <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 操作 -->
      <div class="table-operations">
        <a-button type="danger" :disabled="multiple" @click="handleDelete" v-hasPermi="['workflow:definition:remove']">
          <a-icon type="delete" />删除
        </a-button>
        <a-button type="dashed" @click="$refs.importXml.importExcelHandleOpen()" v-hasPermi="['workflow:definition:import']">
          <a-icon type="import" />导入
        </a-button>
        <a-button
          type="dashed"
          shape="circle"
          :loading="loading"
          :style="{float: 'right'}"
          icon="reload"
          @click="getList" />
      </div>
      <!-- 上传文件 -->
      <import-xml
        ref="importXml"
        @ok="getList"
      />
      <!-- 数据展示 -->
      <a-table
        :loading="loading"
        rowKey="id"
        :columns="columns"
        :data-source="list"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :pagination="false"
        @change="handleTableChange">
        <span slot="operation" slot-scope="text, record">
          <a @click="handleView(record)" v-hasPermi="['workflow:definition:wfImage']">
            <a-icon type="eye" />查看
          </a>
          <a-divider type="vertical" v-hasPermi="['workflow:definition:edit']" />
          <a @click="handleEdit(record)" v-hasPermi="['workflow:definition:edit']">
            <a-icon type="edit" />编辑
          </a>
        </span>
      </a-table>
      <!--查看流程图-->
      <deploy-view ref="deployView"></deploy-view>
    </a-card>
  </page-header-wrapper>
</template>
<script>
import ImportXml from './modules/ImportXml'
import { pageWfDeploy } from '@/api/workflow/workflow'
import DeployView from './modules/deployView'

export default {
  name: 'Deploy',
  components: {
    ImportXml,
    DeployView
  },
  props: {},
  data () {
    return {
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      // 查询条件
      queryParam: {
        wfName: undefined,
        wfCategory: undefined
      },
      // 字段
      columns: [
        {
          title: '流程key',
          dataIndex: 'flowKey',
          align: 'center'
        },
        {
          title: '流程名称',
          dataIndex: 'name',
          align: 'center'
        },
        {
          title: '流程分类',
          dataIndex: 'category',
          align: 'center'
        },
        {
          title: '部署ID',
          dataIndex: 'deploymentId',
          align: 'center'
        },
        {
          title: '部署时间',
          dataIndex: 'deploymentTime',
          align: 'center'
        },
        {
          title: '流程定义状态',
          dataIndex: 'suspensionState',
          align: 'center'
        },
        {
          title: '版本',
          dataIndex: 'version',
          align: 'center'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' },
          align: 'center'
        }
      ],
      // 非多个禁用
      multiple: true,
      total: 0,
      list: []
    }
  },
  watch: {},
  computed: {},
  methods: {
    // 查询
    handleQuery () {

    },
    // 重置
    resetQuery () {

    },
    // 删除流程定义
    handleDelete () {

    },
    // 刷新
    getList () {
      this.loading = true
      pageWfDeploy(this.queryParam).then(res => {
        if (res.code === 200) {
          this.list = res.data.rows
          this.total = res.data.total
          this.loading = false
        }
      })
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.operId)
      this.multiple = !selectedRowKeys.length
    },
    handleTableChange (pagination, filters, sorter) {
      const sort = this.tableSorter(sorter)
      this.queryParam.orderByColumn = sort.orderByColumn
      this.queryParam.isAsc = sort.isAsc
      this.getList()
    },
    // 查看流程图
    handleView (record) {
      this.$refs.deployView.show(record.deploymentId)
    },
    // 编辑流程图
    handleEdit (record) {
      this.$router.push({ path: '/workflow/design', query: { deployId: record.deploymentId } })
    }
  },
  created () {
    this.getList()
  },
  mounted () {}
}
</script>,
<style lang="scss" scoped>
</style>
